package com.ibiaoke.goods.dao;

import com.ibiaoke.common.base.BaseDao;
import com.ibiaoke.common.consts.CommonConsts;
import com.ibiaoke.goods.entity.GoodsClass;
import com.ibiaoke.goods.entity.GoodsClassExample;
import com.ibiaoke.goods.mapper.GoodsClassMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Administrator on 2017/6/7.
 */
@Repository
public class GoodsClassDao extends BaseDao<GoodsClass,GoodsClassExample,Integer,GoodsClassMapper>{
    @Autowired
    private GoodsClassMapper goodsClassMapper;

    @Override
    public GoodsClassMapper getMapper() {
        return goodsClassMapper;
    }
    /**
     * 商品分类
     * @return
     */
    public List<GoodsClass> listGoodsClass(){
        GoodsClassExample example = new GoodsClassExample();
        example.createCriteria().andLevelEqualTo(CommonConsts.YES).andDelStatusEqualTo((byte) CommonConsts.NO);
        example.setOrderByClause("gc_sort");
        return  goodsClassMapper.selectByExample(example);
    }

    /**
     * 删除商品
     * @param goodsClassId
     * @return
     */
    public int deleteByGoodsClassId(Integer goodsClassId) {
        GoodsClassExample example = new GoodsClassExample();
        example.createCriteria().andGcIdEqualTo(goodsClassId);
        GoodsClass goodsClass = new GoodsClass();
        goodsClass.setDelStatus((byte) CommonConsts.YES);
        return goodsClassMapper.updateByExampleSelective(goodsClass, example);
    }


}
